#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1005;

int n, m, k;
char a[N][N];
bool vis[N][N];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void forward(int& x, int& y, int& d) {
  int nx = x + dx[d], ny = y + dy[d];
  if (nx < 1 || nx > n || ny < 1 || ny > m)
    d = (d + 1) % 4;
  else if (a[nx][ny] == 'x')
    d = (d + 1) % 4;
  else
    x = nx, y = ny;
}
void solve() {
  int x0, y0, d0;
  cin >> n >> m >> k;
  cin >> x0 >> y0 >> d0;
  rep(i, 1, n) rep(j, 1, m) cin >> a[i][j];
  rep(i, 1, n) rep(j, 1, m) vis[i][j] = 0;
  vis[x0][y0] = 1;
  rep(i, 1, k) forward(x0, y0, d0), vis[x0][y0] = 1;
  int cnt = 0;
  rep(i, 1, n) rep(j, 1, m) cnt += vis[i][j];
  cout << cnt << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}